package katris.selenium.tests.pages;

import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent;
import static org.openqa.selenium.support.ui.ExpectedConditions.elementToBeClickable;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;
import katris.selenium.tests.model.Film;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.WebDriverWait;

public class ShortMovieInfoPage extends InternalPage {
	
	public ShortMovieInfoPage(PageManager pages) {
		super(pages);
	}
	
	  public ShortMovieInfoPage ensurePageLoaded() {
		    super.ensurePageLoaded();
		    wait.until(visibilityOfElementLocated(By.xpath("//div[@class='maininfo_full']")));
		    return this;
		  }
	  
	  
	  public boolean checkMovieInfo(Film film) {
		  
	      boolean check = true;
	      
		  WebElement movie = wait.until(elementToBeClickable(By.xpath("//div[@class='maininfo_full']")));
	      String text = movie.getText();

	      if (text.contains(film.getTitle())){
	    	  System.out.println("Movie Name is correct");
	          }
	      else {
	      check = false;}

	      if (text.contains(film.getYear())){
	    	  System.out.println("Movie Year is correct");
	      }
	      else {
	          check = false;}

	      if (check == true)  {
	          return true;
	      }
	     else {

	          return false;
	      }
	  }
	  
	  public InternalPage clickRemoveDescription() {
          WebElement movie = wait.until(elementToBeClickable(By.xpath("//img[@title='Remove']")));
          movie.click();
		    wait.until(alertIsPresent()).accept();
		    return pages.internalPage;
		  }
}
